-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable pnpx with cdk init #30661
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a CLI integ test? It would be something like init-typescript-app-npx
, they live here: https://github.com/aws/aws-cdk/tree/main/packages/%40aws-cdk-testing/cli-integ
print(`Got exec path ${chalk.green(`${process.env.npm_execpath}`)}...`); | ||
print(`Got command ${chalk.green(`${'pnpm'}`)}...`); | ||
return 'pnpm'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(`Got exec path ${chalk.green(`${process.env.npm_execpath}`)}...`); | |
print(`Got command ${chalk.green(`${'pnpm'}`)}...`); | |
return 'pnpm'; | |
return 'pnpm'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it and testing as we speak
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we are supporting pnpm. Where is the line for other package managers? We have custom logic for calling pnpx, but what about the next tool?
Would it be better to draw the line somewhere and create custom logic for each manager, or is there a way to map the command we get in to the command we call in init?
@@ -153,10 +153,14 @@ export class InitTemplate { | |||
|
|||
private async installProcessed(templatePath: string, toFile: string, language: string, project: ProjectInfo) { | |||
const template = await fs.readFile(templatePath, { encoding: 'utf-8' }); | |||
await fs.writeFile(toFile, this.expand(template, language, project)); | |||
let appCommandTool = 'npx'; | |||
if (toFile.includes('cdk.json') && await getCommand() === 'pnpm') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard-coded for pnpm, but we wont support yarn or other package managers etc. Is that the approach we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per my understanding we do not want to extend this feature pass pnpm
following the comments in the original issue I think we should just expand the support to pnpm
. Otherwise we expose ourselves into making changes every time there is a possibility of having a new package manager. Any thoughts?
@@ -359,6 +364,16 @@ async function postInstallTypescript(canUseNetwork: boolean, cwd: string) { | |||
} | |||
} | |||
|
|||
async function getCommand(): Promise<string> { | |||
print('Getting command...'); | |||
if (process.env.npm_execpath && process.env.npm_execpath.includes('pnpm')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (process.env.npm_execpath && process.env.npm_execpath.includes('pnpm')) { | |
if (process.env.npm_execpath?.includes('pnpm')) { |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing ✅ A exemption request has been requested. Please wait for a maintainer's review. |
1 similar comment
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing ✅ A exemption request has been requested. Please wait for a maintainer's review. |
Issue # (if applicable)
Closes #23205.
Reason for this change
cdk init
does not usepnpm install
when creating a new project withpnpx cdk init app --language typescript
Description of changes
pnpm install
by resolving the package manager tool used with thecdk init
command.cdk.json
to use a place holder for the app command depending on the package manager tool usednpm install
in case nothing is passedDescription of how you validated changes
Manual testing
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license